using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PmSoft.Cache.Abstractions;
using PmSoft.Cache.Redis;

namespace Demo.Application.Test
{
	public class UnitTest1
	{
		private readonly IServiceProvider ServiceProvider;
		public UnitTest1()
		{
			ServiceProvider = new ServiceCollection()
			   .AddOptions()
			   .AddLogging(option =>
			   {
				   option.AddConsole();
			   })
			   .Configure<RedisCacheOptions>(options =>
			   {
				   options.Configuration = "127.0.0.1:6379,password=123456,connectTimeout=1000,connectRetry=1,syncTimeout=10000,ssl=false,allowAdmin=true";
				   options.InstanceName = "pmsoft_demo:";
			   })
			   .Configure<CacheServiceOptions>(options =>
			   {
				   options.EnableDistributedCache = true;
			   })
			.AddStackExchangeRedisCache(options =>
			{
				//var endPoints = configuration.GetSection("RedisCacheOptions:ConfigurationOptions:EndPoints")
				//.Get<string[]>()?
				//.Select(m => EndPointCollection.TryParse(m)) ?? new List<EndPoint>();
				//foreach (var endPoint in endPoints)
				//{
				//	if (endPoint != null)
				//		options.ConfigurationOptions?.EndPoints.Add(endPoint);
				//}
			})
			.AddMemoryCache()
			.AddSingleton<IRedisCacheProvider, RedisCacheProvider>()
			.AddSingleton<ICacheService, DefaultCacheService>()
			.BuildServiceProvider();
		}

		[Fact]
		public void Test1()
		{

		}
	}
}